package cn.iocoder.yudao.framework.business.evaluation.enums;

import cn.iocoder.yudao.framework.business.basic.enums.EnumValuable;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 评分星级枚举
 *
 * @author 山野羡民
 * @since 2024/5/26 16:56
 */
@Getter
@AllArgsConstructor
public enum ScoreLevelEnum implements EnumValuable {

    STAR_0(0, "0星"),
    STAR_1(1, "1星"),
    STAR_2(2, "2星"),
    STAR_3(3, "3星"),
    STAR_4(4, "4星"),
    STAR_5(5, "5星"),
    ;

    private final Integer value;
    private final String name;

    public static ScoreLevelEnum fromScore(double score) {
        if (score == 0D) {
            return ScoreLevelEnum.STAR_0;
        }
        if (score < 1.5D) {
            return ScoreLevelEnum.STAR_1;
        }
        if (score < 2.5D) {
            return ScoreLevelEnum.STAR_2;
        }
        if (score < 3.5D) {
            return ScoreLevelEnum.STAR_3;
        }
        if (score < 4.5D) {
            return ScoreLevelEnum.STAR_4;
        }
        return ScoreLevelEnum.STAR_5;
    }

}
